package com.dyz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dyz.domain.DTO.NoticeDTO;
import com.dyz.domain.Notice;
import com.dyz.model.Result;
import com.dyz.service.INoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@Api(tags = "公告管理")
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    private INoticeService noticeService;
    @GetMapping("/getList")
    @ApiOperation(value = "获取公告列表")
    @PreAuthorize("hasAuthority('notice_query')")
    public Result<?> getNoticeList(@ApiIgnore Page<Notice> page, String title, String startTime, String endTime, Integer status) {
        return noticeService.getNoticeList(page, title, startTime, endTime, status);
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "获取公告详情")
    @PreAuthorize("hasAuthority('notice_query')")
    public Result<?> getNoticeById(Long id) {
        return Result.success(noticeService.getById(id));
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加公告")
    @PreAuthorize("hasAuthority('notice_create')")
    public Result<?> addNotice(@RequestBody NoticeDTO noticeDTO) {
        return noticeService.insertNotice(noticeDTO);
    }
    @PostMapping("/update")
    @ApiOperation(value = "修改公告")
    @PreAuthorize("hasAuthority('notice_update')")
    public Result<?> updateNotice(@RequestBody NoticeDTO noticeDTO) {
        return noticeService.updateNotice(noticeDTO);
    }
    @PostMapping("/delete")
    @ApiOperation(value = "删除公告")
    @PreAuthorize("hasAuthority('notice_delete')")
    public Result<?> deleteNotice(String ids) {
        return noticeService.deleteNoticeByIds(ids);
    }
    @GetMapping("/updateStatus")
    @ApiOperation(value = "修改公告状态")
    @PreAuthorize("hasAuthority('notice_update')")
    public Result<?> updateNoticeStatus(String id) {
        return noticeService.updateStatusById(id);
    }

}
